package com.ghck.server.model;

import com.ghck.server.exception.EnumOutOfBoundException;
import com.ghck.server.exception.ErrorConstant;

public enum UserRole {

	/**
	 * 0 游客
	 * 1 普通用户
	 * 2 创客
	 * 3 商家
	 * 4 客服
	 * 5 管理员
	 */
	ANYBODY,USER,MAKER,SHOP,CUSTOMER_SERVICE,ADMIN;

    public static UserRole [] all = UserRole.values();
    public static UserRole fromInt(Integer n) throws EnumOutOfBoundException {
        if (n == null) {
            return null;
        } else if (n >= 0 && n < all.length) {
            return all[n];
        } else {
            throw new EnumOutOfBoundException(ErrorConstant.OUT_OF_BUNDRY.getErrorCode(),"the integer " + n + " is beyond the range of 'UserRole' enum type");
        }
    }    
    public static UserRole fromName(String name) throws EnumOutOfBoundException {
        if (name == null) {
            return null;
        } 
        for(UserRole userRole : all){
        	if(userRole.name().equals(name))
        		return userRole;
        }
        return null;
    }
}